package com.xiu.jvm.gc;

public class TestAllocation {
	private static final int _1MB = 1024 * 1024;
	/**
	 * VM args: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
	 * @author wangxinxin
	 *
	 */
	public static void TestAllocation(){
		byte[] allocation1,allocation2,allocation3,allocation4;
		allocation1=new byte[2*_1MB];
		allocation2=new byte[2*_1MB];
		allocation3=new byte[2*_1MB];
		allocation4=new byte[4*_1MB];
	}
	/**
	 * VM args: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=3145728
	 * @author wangxinxin
	 *
	 */
	public static void TestPretenureSizeThreshold(){
		byte[] allocation1;
		allocation1=new byte[4*_1MB];
	}
	/**
	 * VM args: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=1 -XX:+PrintTenuringDistribution
	 * @author wangxinxin
	 *
	 */
	public static void TestTenuringThreshold(){
		byte[] allocation1,allocation2,allocation3;
		allocation1=new byte[_1MB/4];
		allocation2=new byte[4*_1MB];
		allocation3=new byte[4*_1MB];
		allocation3=null;
		allocation3=new byte[4*_1MB];
	}
	
	/**
	 * VM args: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=15 -XX:+PrintTenuringDistribution
	 * @author wangxinxin
	 *
	 */
	public static void TestTenuringThreshold2(){
		byte[] allocation1,allocation2,allocation3,allocation4,allocation5,allocation6;
		allocation1=new byte[_1MB/4];
		allocation2=new byte[_1MB/4];
		allocation3=new byte[4*_1MB];
		allocation4=new byte[4*_1MB];
		allocation5=null;
		allocation6=new byte[4*_1MB];
	}
	/**
	 * VM args: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:-HandlePromotionFailure
	 * @author wangxinxin
	 *
	 */
	public static void TestHandlePromotion(){
		byte[] allocation1,allocation2,allocation3,allocation4,allocation5,allocation6,allocation7;
		allocation1=new byte[2*_1MB];
		allocation2=new byte[2*_1MB];
		allocation3=new byte[2*_1MB];
		allocation1=null;
		allocation4=new byte[2*_1MB];
		allocation5=new byte[2*_1MB];
		allocation6=new byte[2*_1MB];
		allocation4=null;
		allocation5=null;
		allocation6=null;
		allocation7=new byte[2*_1MB];
	}
	
	public static void main(String[] args) {
//		TestAllocation();
//		TestPretenureSizeThreshold();
//		TestTenuringThreshold();
//		TestTenuringThreshold2();
		TestHandlePromotion();
		
	}

}
